package com.etoak.controller;

import com.etoak.service.LikeService;
import com.etoak.vo.LikeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/like")
public class LikeController {

    @Autowired
    LikeService likeService;

    public static final String LIKE_KEY_PREFIX = "like:image:";

    @RequestMapping("/image/{id}/user/{name}")
    public LikeVo like(@PathVariable String id, @PathVariable String name) {
        String key = LIKE_KEY_PREFIX + id;
        boolean like = likeService.like(key,name);
        Long count = likeService.getCount(key);

        LikeVo vo = new LikeVo(count,like);

        return vo;
    }
}
